package com.kcwl.carrier.interfaces.inner;

import com.kcwl.carrier.application.service.CarrierDriverApplicationService;
import com.kcwl.carrier.interfaces.command.CarrierAddDriverCommand;
import com.kcwl.carrier.interfaces.command.CarrierDriverCommand;
import com.kcwl.carrier.interfaces.command.HandleWaitingCommand;
import com.kcwl.carrier.interfaces.command.IdCommand;
import com.kcwl.carrier.interfaces.dto.CarrierDriverDTO;
import com.kcwl.carrier.interfaces.dto.CarrierInfoDTO;
import com.kcwl.carrier.interfaces.dto.ChiefDTO;
import com.kcwl.carrier.interfaces.query.*;
import com.kcwl.carrier.interfaces.query.CarrierDriverQuery;
import com.kcwl.carrier.interfaces.query.IdQuery;
import com.kcwl.carrier.interfaces.query.MyCarriersQuery;
import com.kcwl.carrier.interfaces.query.SearchQuery;
import com.kcwl.ddd.infrastructure.api.ResponseMessage;
import com.kcwl.framework.rest.helper.ResponseHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lxp
 * @date 2023/1/10 14:08
 * @Description
 */
@Validated
@RestController
@Api(tags = "老板司机关系")
@RequestMapping("/carrier/carrierDriver")
public class CarrierDriverController {

    @Autowired
    CarrierDriverApplicationService carrierDriverApplicationService;

    @ApiOperation(value = "新增老板司机关系")
    @PostMapping("/createCarrierDriver")
    public ResponseMessage createCarrierDriver(@RequestBody CarrierDriverCommand carrierDriverCommand) {
        carrierDriverApplicationService.createCarrierDriver(carrierDriverCommand);
        return ResponseHelper.success();
    }

    @ApiOperation(value = "修改老板司机关系")
    @PostMapping("/updateCarrierDriverInfo")
    public ResponseMessage updateCarrierDriverInfo(@RequestBody CarrierDriverCommand carrierDriverCommand) {
        carrierDriverApplicationService.updateCarrierDriverInfo(carrierDriverCommand);
        return ResponseHelper.success();
    }

    @ApiOperation(value = "查询老板司机关系")
    @PostMapping("/queryCarrierDriver")
    public ResponseMessage queryCarrierDriver(@RequestBody CarrierDriverQuery carrierDriverQuery) {
        List<CarrierDriverDTO> carrierDriverDTOList = carrierDriverApplicationService.queryCarrierDriver(carrierDriverQuery);
        return ResponseHelper.success(carrierDriverDTOList);
    }

    @ApiOperation(value = "我的车老板信息(车老板和物流公司)")
    @PostMapping("/queryAllMyCarriers")
    public ResponseMessage queryAllMyCarriers(@RequestBody IdQuery idQuery) {
        List<CarrierInfoDTO> carrierInfoDTOList = carrierDriverApplicationService.queryAllMyCarriers(idQuery);
        return ResponseHelper.successList(carrierInfoDTOList);
    }

    @ApiOperation(value = "车老板邀请司机加入车队")
    @PostMapping("/carrierAddDriver")
    public ResponseMessage carrierAddDriver(@RequestBody CarrierAddDriverCommand command) {
        return ResponseHelper.success(carrierDriverApplicationService.carrierAddDriver(command));
    }
    @ApiOperation(value = "车老板查看我的司机列表")
    @PostMapping("/queryMyDrivers")
    public ResponseMessage queryMyDrivers(@Validated @RequestBody CarrierAndDriverQuery query) {
        return ResponseHelper.successList(carrierDriverApplicationService.queryMyDrivers(query));
    }

    @ApiOperation(value = "车老板搜索可收纳的司机")
    @PostMapping("/searchDrivers")
    public ResponseMessage searchDrivers(@Validated @RequestBody CarrierInfoQuery query) {
        return ResponseHelper.success(carrierDriverApplicationService.searchDrivers(query));
    }

    @ApiOperation(value = "车老板同意/拒绝司机申请加入车队的邀请")
    @PostMapping("/carrierHandleWaiting")
    public ResponseMessage carrierHandleWaiting(@RequestBody HandleWaitingCommand command) {
        return ResponseHelper.success(carrierDriverApplicationService.carrierHandleWaiting(command));
    }

    @ApiOperation(value = "司机申请加入车队")
    @PostMapping("/driverAddCarrier")
    public ResponseMessage driverAddCarrier(@RequestBody CarrierAddDriverCommand command) {
        return ResponseHelper.success(carrierDriverApplicationService.driverAddCarrier(command));
    }

    @ApiOperation(value = "司机查找车队长")
    @PostMapping("/searchCarriers")
    public ResponseMessage<List<ChiefDTO>> searchCarriers(@RequestBody SearchQuery query) {
        return ResponseHelper.success(carrierDriverApplicationService.searchCarriers(query));
    }

    @ApiOperation(value = "司机同意/拒绝车队长的雇佣邀请")
    @PostMapping("/driverHandleWaiting")
    public ResponseMessage driverHandleWaiting(@RequestBody HandleWaitingCommand command) {
        return ResponseHelper.success(carrierDriverApplicationService.driverHandleWaiting(command));
    }

    @ApiOperation(value = "司机解绑车队")
    @PostMapping("/driverDelCarrier")
    public ResponseMessage driverDelCarrier(@RequestBody IdCommand command) {
        return ResponseHelper.success(carrierDriverApplicationService.driverDelCarrier(command));
    }

    @ApiOperation(value = "司机恢复与车老板的合作")
    @PostMapping("/driverRecoverRelation")
    public ResponseMessage driverRecoverRelation(@RequestBody IdCommand command) {
        return ResponseHelper.success(carrierDriverApplicationService.driverRecoverRelation(command));
    }

    @ApiOperation(value = "车老板解除司机")
    @PostMapping("/carrierDelDriver")
    public ResponseMessage carrierDelDriver(@RequestBody IdCommand command) {
        return ResponseHelper.success(carrierDriverApplicationService.carrierDelDriver(command));
    }

    @ApiOperation(value = "车老板恢复与司机关系")
    @PostMapping("/carrierRecoverRelation")
    public ResponseMessage carrierRecoverRelation(@RequestBody IdCommand command) {
        return ResponseHelper.success(carrierDriverApplicationService.carrierRecoverRelation(command));
    }

    @ApiOperation(value = "我的车老板列表")
    @PostMapping("/queryMyCarriers")
    public ResponseMessage queryMyCarriers(@RequestBody MyCarriersQuery query) {
        return ResponseHelper.success(carrierDriverApplicationService.queryMyCarriers(query));
    }
}
